<template>
    <div>
      <AplidForm
        ref="formRef"
        v-bind="formConfig"
        v-model="formModel"
        @reset = "refresh"
        @submit="onSubmit"
        >
      </AplidForm>
    </div>
  </template>
  
  <script setup lang="ts">
  import {ref} from 'vue'
  import apiMod from '@/apiMod/index'
  import { formConfig } from '../../config'
  type Props = {
    nowRowData?:any,
    operateType?:any,
  }
 
let props = withDefaults(defineProps<Props>(),{
    nowRowData:{},
    operateType:'add',
})
  const emit = defineEmits(['refresh','back'])
  const formModel:any = ref({})
    formModel.value = props.nowRowData
  const formRef = ref()
  
  const onSubmit = async(form, done) => {
    console.log('form',form)
    if(props.operateType=='add'){
      try{
        // form.tableId = 
        let res = apiMod.view_bscAssessTableItem_add(form)
        refresh()
      if(res){
        done()
      }
      }catch{
        done()
      }
    }else{
      try{
        let res = apiMod.view_bscAssessTableItem_edit(form)
        refresh()
          if(res){
            done()
          }
      }catch{
        done()
      }
    }
  }
  const refresh = () =>{
    emit('refresh')
  }
  const onSave = () => {
    formRef.value!.onSubmit()
  }
  defineExpose({
    onSave
  })
  </script>
  
  <style scoped></style>
  